home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / metkit / m4wrap.h < prev    next >
C/C++ Source or Header  |  1997-06-07  |  3KB  |  134 lines

  1. //    Copyright (C) 1996, 1997 Meta Four Software.  All rights reserved.
  2. //
  3. //    This file contains the declaration of standard strings / collections.
  4. //
  5. //! rev="$Id: m4wrap.h,v 1.8 1997/06/06 15:20:30 jcw Rel $"
  6.  
  7. #ifndef __M4WRAP_H__
  8. #define __M4WRAP_H__
  9.  
  10. #include <string>
  11. #include <vector>
  12.  
  13. #if !defined (d4_std)            // the default is to use namespaces
  14.     #define d4_std std
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Declarations in this file
  19.  
  20.     class c4_String;
  21.  
  22. //    class c4_ArrayT;
  23. //        class c4_PtrArray;
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26.  
  27. class c4_String : public d4_std::string
  28. {
  29.     typedef d4_std::string string;
  30.  
  31. public:
  32.     c4_String ();
  33.     c4_String (char ch, int nDup =1);
  34.     c4_String (const char* str);
  35.     c4_String (const void* ptr, int len);
  36.     c4_String (const d4_std::string& s);
  37.     c4_String (const c4_String& s);
  38.     ~c4_String ();
  39.  
  40.     const c4_String& operator= (const c4_String&);
  41.  
  42.     operator const char* () const;
  43.  
  44.     char operator[] (int i) const;
  45.     
  46.     friend c4_String operator+ (const c4_String&, const c4_String&);
  47.     friend c4_String operator+ (const c4_String&, const char*);
  48.     friend c4_String operator+ (const char*, const c4_String&);
  49.  
  50.     const c4_String& operator+= (const c4_String& s);
  51.     const c4_String& operator+= (const char* s);
  52.     
  53.     int GetLength() const;
  54.     bool IsEmpty() const;
  55.     void Empty();
  56.     
  57.     c4_String Mid(int nFirst, int nCount =25000) const;
  58.     c4_String Left(int nCount) const;
  59.     c4_String Right(int nCount) const;
  60.                     
  61.     int Compare(const char* str) const;
  62.     int CompareNoCase(const char* str) const;
  63.     
  64.     bool operator< (const c4_String& str) const;
  65.  
  66.     int Find(char ch) const;
  67.     int ReverseFind(char ch) const;
  68.     int FindOneOf(const char* set) const;
  69.     
  70.     int Find(const char* sub) const;
  71.     
  72.     c4_String SpanIncluding(const char* set) const;
  73.     c4_String SpanExcluding(const char* set) const;
  74. };
  75.  
  76. bool operator== (const c4_String&, const c4_String&);
  77. bool operator!= (const c4_String&, const c4_String&);
  78.     
  79. bool operator== (const c4_String& s1, const char* s2);
  80. bool operator== (const char* s1, const c4_String& s2);
  81.  
  82. bool operator!= (const c4_String& s1, const char* s2);
  83. bool operator!= (const char* s1, const c4_String& s2);
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86.  
  87. template<class T>
  88. class c4_ArrayT
  89. {
  90.     d4_std::vector< T, d4_std::allocator<T> > _base;
  91.  
  92. public:
  93.     c4_ArrayT ()                            { }
  94.     ~c4_ArrayT ()                            { }
  95.  
  96.     int GetSize() const                        { return _base.size(); }
  97.     void SetSize(int nNewSize, int =-1)        { _base.resize(nNewSize); }
  98.  
  99.     T GetAt(int nIndex) const                { return _base[nIndex]; }
  100.     T& ElementAt(int nIndex)                { return _base[nIndex]; }
  101.  
  102.     void SetAt(int nIndex, const T& newElement)
  103.     {
  104.         _base[nIndex] = newElement;
  105.     }
  106.  
  107.     int Add(const T& newElement)
  108.     {
  109.         int n = _base.size();
  110.         _base.push_back(newElement);
  111.         return n;
  112.     }
  113.  
  114.     void InsertAt(int nIndex, const T& newElement, int nCount =1)
  115.     {
  116.         _base.insert(&_base[nIndex], nCount, newElement);
  117.     }
  118.  
  119.     void RemoveAt(int nIndex, int nCount =1)
  120.     {
  121.         _base.erase(&_base[nIndex], &_base[nIndex+nCount]);
  122.     }
  123. };
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126.  
  127. #if q4_INLINE
  128.     #include "m4wrap.inl"
  129. #endif
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132.  
  133. #endif
  134.